//+------------------------------------------------------------------+ //| SupportResistTrade.mq4 | //| Copyright © 2008, Gryb Alexander | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2008, Gryb Alexander" #property link "" extern int numBars = 55; extern int maPeriod = 500; extern int Lots = 1; extern double TrailingStop = 50; double support; double resist; string trendType; int timeFrame = 1; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- ObjectCreate("lineSupport",OBJ_HLINE,0,0,0); ObjectSet("lineSupport",OBJPROP_COLOR,Blue); ObjectCreate("lineResist",OBJ_HLINE,0,0,0); ObjectSet("lineResist",OBJPROP_COLOR,Red); ObjectCreate("lblTrendType",OBJ_LABEL,0,0,0,0,0); ObjectSet("lblTrendType",OBJPROP_XDISTANCE,50); ObjectSet("lblTrendType",OBJPROP_YDISTANCE,50); ObjectSetText("lblTrendType","TrendType",14,"Tahoma",Red); //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- ObjectsDeleteAll(); //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- MarketAnalize(); if(OrdersTotal()==0) CheckForOpen(); else CheckForClose(); //---- return(0); } void MarketAnalize() { // --------------------------------------- support = 10000; resist = 0; for(int k = 1;k<=numBars;k++) { if(support>iLow(Symbol(),timeFrame,k)) support = iLow(Symbol(),timeFrame,k); if(resistma) { trendType = "bullish"; } if(Open[0]resist) OrderSend(Symbol(),OP_BUY,Lots,Ask,3,support,0,"Support & Resistance trader",0,0,Green); } if(trendType=="bearish") { if(Bid0) { if(OrderType()==OP_BUY) { if(Bidresist) OrderClose(OrderTicket(),OrderLots(),Ask,3); } } //Trailing if(OrderType()==OP_BUY) { if(TrailingStop>0) { if(Bid-OrderOpenPrice()>Point*TrailingStop) { if(OrderStopLoss()OrderOpenPrice()+Point*20)&&(OrderStopLoss()<(OrderOpenPrice()+Point*10))) // OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*10,OrderTakeProfit(),0,Blue); // if((Ask>OrderOpenPrice()+Point*40)&&(OrderStopLoss()<(OrderOpenPrice()+Point*20))) // OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*20,OrderTakeProfit(),0,Blue); // if((Ask>OrderOpenPrice()+Point*60)&&(OrderStopLoss()<(OrderOpenPrice()+Point*30))) // OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*30,OrderTakeProfit(),0,Blue); // } if(OrderType()==OP_SELL) { if(TrailingStop>0) { if((OrderOpenPrice()-Ask)>(Point*TrailingStop)) { if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red); return(0); } } } // if((Bid(OrderOpenPrice()-Point*10))) // OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*10,OrderTakeProfit(),0,Blue); // if((Bid(OrderOpenPrice()-Point*20))) // OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*20,OrderTakeProfit(),0,Blue); // if((Bid(OrderOpenPrice()-Point*30))) // OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*30,OrderTakeProfit(),0,Blue); } }